package com.example.controller;

import com.example.entity.SysUser;
import com.example.service.SysUserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@RequestMapping("sysUser")
@RestController
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    @RequestMapping("register")
    public SysUser register() {
        SysUser sysUser = new SysUser();
        sysUser.setName(UUID.randomUUID().toString());
        sysUser.setPhone("18721420863");
        sysUserService.saveAndRegister(sysUser);
        return sysUser;
    }

    @RequestMapping("batchRegister")
    public int batchRegister(@RequestParam int count) {
        List<SysUser> list = new ArrayList<>();
        for (int i = 1; i < count; i++) {
            SysUser sysUser = new SysUser();
            sysUser.setName(UUID.randomUUID().toString());
            sysUser.setPhone("18721420863");
            list.add(sysUser);
        }
        sysUserService.saveAndBatchRegister(list);
        return list.size();
    }

}
